package com.lm.sse.controller;

import com.lm.sse.service.SsePushService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
public class SsePushController {

    private SsePushService ssePushService;

    public SsePushController(SsePushService ssePushService) {
        this.ssePushService = ssePushService;
    }

    @GetMapping("/sse/subscribe")
    public SseEmitter subscribe() {
        return ssePushService.subscribe();
    }

    @GetMapping("/sse/push")
    public void pushMessage() {
        ssePushService.pushMessage("当前时间：" + System.currentTimeMillis());
    }
}
